package com.weiyi.chat.presenter;

import android.app.Activity;

import com.google.gson.Gson;
import com.weiyi.chat.api.ISystemMsg;
import com.weiyi.chat.api.IUserList;
import com.weiyi.chat.common.MyStringCallBack;
import com.weiyi.chat.domain.SystemMsgList;
import com.weiyi.chat.domain.UserList;
import com.weiyi.chat.ui.activity.SystemMsgActivity;
import com.weiyi.chat.ui.fragment.MessageFragment;
import com.weiyi.chat.utils.MyReusouce;
import com.zhy.http.okhttp.OkHttpUtils;

/**
 * Created by Lee on 2017/8/24 0024.
 */

public class SystemMsgPresenter implements ISystemMsg.presenter {

    private SystemMsgActivity mView;

    public SystemMsgPresenter(SystemMsgActivity systemMsgActivity) {
        mView = systemMsgActivity;
    }


    @Override
    public void requestSystemMsg() {
        OkHttpUtils.post()
                .url(MyReusouce.SYSTEM_MSG_LIST_URL)
                .addParams("submit", "1")
                .build()
                .execute(new MyStringCallBack(mView) {
                    @Override
                    public void onRequestSucess(String response) {
                        Gson gson = new Gson();
                        SystemMsgList userList = gson.fromJson(response, SystemMsgList.class);
                        mView.onResetSucess(userList.getBody());
                    }

                    @Override
                    public void onRequstFail(String errorInfo) {
                        mView.showError(errorInfo);
                    }
                });
    }

    @Override
    public void loadingDatasFromCache() {

    }
}
